# -*- coding: utf-8 -*-
"""
Created on 15-12-28 下午3:57
@file: cookie.py
@author: Liangrong Li
@contact: liliangrong0@126.com
@description: 打印cookie
"""
"""打印cookie"""

import urllib2
import cookielib

# 声明一个CookieJar对象实例来保存cookie
cookie = cookielib.CookieJar()

# 利用urllib2的HTTPCookieProcessor对象来创建cookie处理器
handler = urllib2.HTTPCookieProcessor(cookie)

# 通过handler来构建opener
opener = urllib2.build_opener(handler)

# 此处的open方法同urllib2的urlopen方法，也可以传入Request
resp = opener.open('http://www.baidu.com')

# 打印出cookie数据
for item in cookie:
    print 'name = ' + item.name
    print 'value = ' + item.value
